package cha;

import static org.junit.Assert.assertFalse;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IBulletSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Test if bullet power fired at the enemy is greater than 2.4.
 *
 *@author Hansen Cheng 
 */
public class TestFire extends RobotTestBed {

  // True if Destroyer robot has fired a bullet with power greater than 2.4;
  boolean firePower = false;
  
  /**
   * Specifies that SittingDuck and Destroyer robot.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override public String getRobotNames() {

    return "sample.SittingDuck,cha.Destroyer";
  }
  
  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds. 
   */
  @Override public int getNumRounds() {
    
    return 10;
  }
  
  /**
   * At the end of each turn it will test if the firepower is greater than 
   * or equal to 10.
   * 
   * @param event - to catch the action of the robot after the turn ends.
   */
  @Override public void onTurnEnded (TurnEndedEvent event) {
    
    // All active bullets belong to Destroyer since SittingDuck does not fire.
    IBulletSnapshot bullets[] = event.getTurnSnapshot().getBullets();
    double bulletPower;
    
    for (int i = 0; i < bullets.length; i++) {
    
      bulletPower = bullets[i].getPower();
      if (bulletPower >= 10) {
        firePower = true;
      }
    }
  }
  
  /**
   * After running all matches, determine if DaCruzer has had variability in its bullet power.
   * 
   * @param event Details about the completed battle.
   */
  @Override public void onBattleCompleted(BattleCompletedEvent event) {
    assertFalse("Bullet Power greater than or equal to 10", firePower);
  }
}